<?php
namespace app\common\model;


class Comment extends Base
{
    protected $hidden = ['update_time']; //设置自动隐藏的字段

    public function user()
    {
        //传参:关联模型、关联字段、本模型的主键
        return $this->belongsTo('user', 'uid', 'id');
    }

    protected function initialize()
    {
        parent::initialize();
    }


    
    public static function index(){
        $input = input();
        $page = $input['page'];
        if($page<=0){
            $page = 1;
        };
        $page_num=20;
        $start_pos = $page_num*($page-1);
        //关联User表查询user信息
        $comments = self::with(['user'])
                    ->where('goods_id', $input['goods_id'])
                    ->order('create_time desc')
                    ->limit($start_pos, $page_num)
                    ->select();
        return $comments;

    }

    
}